<?php
/**
 * Created by IntelliJ IDEA.
 * User: yvdedu.com
 * Date: 2017/3/30
 * Time: 14:53
 */

namespace Blog\Controller;
use Common\Controller\AdminbaseController;


class IndexcountryController extends AdminbaseController
{
    function Countrylist()
    {//游学国家列表
        $where = array();
        $request = I('request.');
        $dd_id = I('request.Country_id');

        if (!empty($request['Country_id'])) {
            $where['id'] = intval($request['Country_id']);
        }

        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];
            $keyword_complex = array();
            $keyword_complex['Country_id'] = array('like',"%$keyword%");
            $keyword_complex['country'] = array('like', "%$keyword%");
            $keyword_complex['_logic'] = 'or';
            $where['_complex'] = $keyword_complex;
        }
        if ($dd_id){
            $where['Country_id'] = array('like',"%$dd_id%");
        }

        $users_model = M("Country");

        $count = $users_model->where($where)->count();
        $page = $this->page($count, 20);

        $list = $users_model
            ->where($where)
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));
        $this->display();
    }

    function addCountrylist(){
        $Country = I('country');

        var_dump($Country);
        if (!empty($Country)) {
            $cmf_country = M("country");
            $xt = $cmf_country->find();
            if (empty($xt)) {
                $this->ajaxReturn(333);
            } else {
                if (!empty($Country)) {
                    $data['Country'] = $Country;
                    var_dump($data);
                    if (!empty($data)) {
                        $cmf_country->add($data);
                        $this->success("添加成功");
                    }
                } else {
                    $this->error("添加失败");
                }
            }
        }
    }
    function deletecoun(){
        $id = I('id');
        var_dump($id);
        if (!empty($id)) {
            $cmf_country = M("country");
            $cmf_country->where("country_id=$id")->delete();
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }
    }
}